

package com.idcos.enterprise.portal.dal.repository;

// auto generated imports

import com.idcos.cloud.core.dal.common.jpa.BaseRepository;
import com.idcos.enterprise.portal.dal.entity.PortalPermission;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * 自动生成PortalPermissionRepository
 * <p>
 * 数据库配置文件自动生成,此文件属于自动生成的,具体可以参考codegen工程
 * Generated by <tt>jap-codgen</tt> on 2015-11-07 10:08:49.
 *
 * @author system-user
 * @version PortalPermissionRepository.java, v 1.1 2015-11-07 10:08:49 system-user Exp $
 */
public interface PortalPermissionRepository extends BaseRepository<PortalPermission, String> {

    /**
     * <p>
     * The jql statement for this operation is <br>
     * <tt>select p.authResId from PortalPermission p where p.authObjType=?1 and p.authResType=?2 and p.authObjId=?3</tt>
     *
     * @param authObjType
     * @param authResType
     * @param authObjId
     * @return List<String>
     */
    @Query("select p from PortalPermission p where p.authObjType=?1 and p.authResType=?2 and p.authObjId=?3")
    List<PortalPermission> queryAuthRes(String authObjType, String authResType, String authObjId);

    /**
     * <p>
     * The jql statement for this operation is <br>
     * <tt>select p.authObjId from PortalPermission p where p.authObjType=?1 and p.authResType=?2 and p.authResId=?3</tt>
     *
     * @param authObjType
     * @param authResType
     * @param authResId
     * @return List<String>
     */
    @Query("select p from PortalPermission p where p.authObjType=?1 and p.authResType=?2 and p.authResId=?3")
    List<PortalPermission> queryAuthObj(String authObjType, String authResType, String authResId);

    /**
     * 根据appId和authResType查询权限
     *
     * @param appId
     * @param authResType
     * @return
     */
    @Query("select p from PortalPermission p where p.appId=?1 and p.authResType=?2")
    List<PortalPermission> queryAuthObjByAppIdAndAuthResType(String appId, String authResType);

    /**
     * <p>
     * The jql statement for this operation is <br>
     * <tt>delete from PortalPermission s where s.authResId = ?1 and s.authObjId = ?2</tt>
     *
     * @param authResId
     * @param authObjId
     * @return int
     */
    @Query("delete from PortalPermission s where s.authResId = ?1 and s.authObjId = ?2")
    @Modifying
    int deleteByAuthResIdAndAuthObjId(String authResId, String authObjId);

    /**
     * <p>
     * The jql statement for this operation is <br>
     *
     * @param authObjType
     * @param authObjId
     * @return List<PortalPermission>
     */
    List<PortalPermission> queryAuthResByAuthObjTypeAndAuthObjId(String authObjType, String authObjId);

    /**
     * 根据authObjId查询权限
     *
     * @param authObjId
     * @return
     */
    List<PortalPermission> findByAuthObjId(String authObjId);


    /**
     * <p>
     * select distinct p.authResId from PortalPermission p where p.authObjType=?1 and p.authObjId in ?2<br>
     *
     * @param appId
     * @param roleList
     * @return
     */
    @Query("select  p from PortalPermission p where p.appId=?1 and p.authObjId in ?2")
    List<PortalPermission> queryAuthIdsByAuthObjs(String appId, Set<String> roleList);

}